package com.gjszn.intercepter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.gjszn.constant.SysConfig;

/**    
* @Title: AdminIntercepterHandler.java  
* @Package com.gjszn.intercepter    
* @author jys@nx-yt.com    
* @date 2015年11月16日 下午4:33:07  
* @version V1.0    
* @Description: TODO(用一句话描述该文件做什么)
********************************************/
public class AdminIntercepterHandler extends HandlerInterceptorAdapter {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		String admin = (String)request.getSession().getAttribute(SysConfig.ADMIN_USER);
		if(admin == null || "".endsWith(admin)){
//			response.sendRedirect( request.getContextPath() +  "/mgr/login");
//			return false;
			
			request.getSession().setAttribute(SysConfig.ADMIN_USER, "admin");
		}
		return super.preHandle(request, response, handler);
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		// TODO Auto-generated method stub
		super.postHandle(request, response, handler, modelAndView);
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		// TODO Auto-generated method stub
		super.afterCompletion(request, response, handler, ex);
	}

	@Override
	public void afterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		// TODO Auto-generated method stub
		super.afterConcurrentHandlingStarted(request, response, handler);
	}
	
}

